/*
 * Created on 2004-10-9
 *
 * To change the template for this generated file go to
 * Window&gt;Preferences&gt;Java&gt;Code Generation&gt;Code and Comments
 */
package com.mao.util;

import java.io.Serializable;

import org.apache.commons.lang.StringUtils;


/**
 * @author tiyi 2004-10-9
 */
public class Validator {


	public static boolean isEmpty(Serializable s) {

		if (s == null)
			return true;

		return isEmpty(s.toString());

	}

	public static boolean isEmpty(String s) {

		if (s == null)
			return true;
		if (s.trim().equals(""))
			return true;
		return false;
	}

	public static boolean isEmpty(Object[] array) {

		if (array == null)
			return true;

		if (array.length == 0)
			return true;

		return false;
	}

	public static boolean isNo(String no) {
		if (isEmpty(no))
			return false;

		String str = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_-";

		if (no.length() > 40) {
			return false;
		}

		if (!StringUtils.containsOnly(no, str.toCharArray()))
			return false;
		return true;
	}

	/**
	 * @param l
	 * @return
	 */
	public static boolean isValidId(long l) {
		if (l <= 0)
			return false;
		else
			return true;
	}

	public static boolean isEquals(String s1, String s2) {
		if (!isEmpty(s1)) {
			if (isEmpty(s2)) {
				return false;
			} else {
				return s1.equals(s2);
			}
		} else {
			if (isEmpty(s2)) {
				return true;
			} else {
				return false;
			}
		}
	}
}
